package com.atguigu.tingshu.user.startegy;

import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author：yyj
 * @Package：com.atguigu.tingshu.user.startegy
 * @Project：tingshu_parent240829
 * @name：ProcessAlbumOrderTypePayRecord
 * @Date：2025/2/13 16:31
 * @Filename：ProcessAlbumOrderTypePayRecord
 */
@Component(value = "1001")
@Slf4j
public class ProcessAlbumOrderTypePayRecord implements ProcessDiffPayRecord{
    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;

    @Override
    public void processPayRecord(UserPaidRecordVo userPaidRecordVo) {
        String orderNo = userPaidRecordVo.getOrderNo();
        UserPaidAlbum userPaidAlbum = userPaidAlbumMapper.selectOne(new LambdaQueryWrapper<UserPaidAlbum>().eq(UserPaidAlbum::getOrderNo, orderNo));
        if (userPaidAlbum != null) {
            throw new GuiguException(201, "该专辑类型订单支付流水已存在");
        }
        userPaidAlbum = new UserPaidAlbum();
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        int insert = userPaidAlbumMapper.insert(userPaidAlbum);
        log.info("保存订单：{}，记录支付流水:{}", orderNo, insert > 1 ? "成功" : "失败");
    }
}